<script setup>
import * as _ from 'lodash'
import { onUnmounted } from 'vue'
const emits = defineEmits(['sketch', 'submit', 'next'])
const props = defineProps({
  isEnd: {
    type: Boolean,
    default: false,
  },
  contractDetail: {
    type: Object,
    default: () => {},
  },
})
const _throttle_next = _.throttle(handleNextClick, 1000, {
  leading: true,
  trailing: false,
})
const _throttle_submit = _.throttle(handleSubmitClick, 1000, {
  leading: true,
  trailing: false,
})
function handleSketchClick() {
  emits('sketch')
}
function handleSubmitClick() {
  emits('submit')
}
function handleNextClick() {
  emits('next')
}
onUnmounted(() => {
  _throttle_next.cancel()
  _throttle_submit.cancel()
})
</script>

<template>
  <div class="step__tool">
    <div
      class="step__tool-btn sketch"
      @click="handleSketchClick"
      v-if="[undefined, 'Draft'].includes(contractDetail.contractStatus)"
    >
      暂存为草稿
    </div>
    <div v-if="props.isEnd" class="step__tool-btn" @click="_throttle_submit"  :style="{width:[undefined, 'Draft'].includes(contractDetail.contractStatus) ? '':'100%'}">
      提交
    </div>
    <div v-else class="step__tool-btn" :style="{width:[undefined, 'Draft'].includes(contractDetail.contractStatus) ? '':'100%'}" @click="_throttle_next">下一步</div>
  </div>
</template>

<style lang="scss" scoped>
.step__tool {
  width: 100%;
  height: 88px;
  background: #ffffff;
  display: flex;
  justify-content: space-between;
  padding: 10px 20px;
  position: fixed;
  bottom: 0;
  .step__tool-btn {
    width: 160px;
    height: 48px;
    background: #3f84f3;
    border-radius: 24px;
    text-align: center;
    line-height: 48px;
    color: #ffffff;
    &.sketch {
      background: #eaf2ff;
      color: #3f84f3;
    }
  }
}
</style>
